package cn.com.system.controller;

import io.swagger.annotations.Api;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.system.service.impl.HttpSessionService;
import cn.com.util.TsBqUtils;


/**
 * 视图
 *
 * @author wenbin
 * @version V1.0
 * @date 2020年3月18日
 */
@Api(tags = "服务端口视图")
@Controller
@RequestMapping("/index")
public class IndexServerController {
	
	@Value("${gasstation.projectname}")
	private String projectname;
	@Autowired
	private HttpSessionService httpSessionService;
	
	
	@GetMapping("/login")
	public String logout(Model model) {
		
		model.addAttribute("projectname", projectname);
		
		Subject subject = SecurityUtils.getSubject();
		if (subject.isAuthenticated()) {
			return "redirect:/index/home";
		}
		return "login";
	}

	@GetMapping("/home")
	public String home(Model model, String userId, String taxcode, String token,String roles) {
		
		String resView = "";
		model.addAttribute("userId", userId);
		model.addAttribute("taxcode", taxcode);
		model.addAttribute("token", token);
		// String currentRolesId = httpSessionService.getCurrentRolesId();
		String currentRolesId = httpSessionService.getCurrentRolesIdNew(token,userId);
		
		if(TsBqUtils.isNotNull(roles)){
			// 切换身份
		}else{
			if(TsBqUtils.isNull(currentRolesId)){
				return "redirect:/index/login";
			}else{
				// 当前登录
				if(currentRolesId.contains("1893827506289520641")){
					resView = "home_nr";
				}else{
					resView = "home";
				}
			}
			
		}
		return resView;
	}

	@GetMapping("/users/password")
	public String updatePassword() {
		return "users/update_password";
	}

	@GetMapping("/users/info")
	public String userDetail(Model model) {
		model.addAttribute("flagType", "edit");
		return "users/user_edit";
	}
	
	@GetMapping("/users/identity")
	public String userIdentity(Model model) {
		model.addAttribute("flagType", "edit");
		return "users/user_identity";
	}
	
	@GetMapping("/menus")
	public String menusList() {

		return "menus/menu_list";
	}

	@GetMapping("/roles")
	public String roleList() {
		return "roles/role_list";
	}

	@GetMapping("/users")
	public String userList() {
		return "users/user_list";
	}

	@GetMapping("/logs")
	public String logList() {
		return "logsmanage/log_list";
	}

	@GetMapping("/depts")
	public String deptList() {
		return "depts/dept_list";
	}

	@GetMapping("/403")
	public String error403() {
		return "error/403";
	}

	@GetMapping("/404")
	public String error404() {
		return "error/404";
	}

	@GetMapping("/500")
	public String error405() {
		return "error/500";
	}
	
	/**
	 * 油站首页
	 * @return
	 */
	@GetMapping("/main")
	public String main() {
		return "main";
	}

	/**
	 * 自然资源首页
	 * @return
	 */
	@GetMapping("/main_nr")
	public String mainNr() {
		return "main_nr";
	}
	
	
	@GetMapping("/error405")
	public String errornew() {
		return "error405";
	}

	

	

	@GetMapping("/build")
	public String build() {
		return "build";
	}

	@GetMapping("/sysContent")
	public String sysContent() {
		return "syscontent/list";
	}

	@GetMapping("/sysDict")
	public String sysDict() {
		return "sysdict/list";
	}

	@GetMapping("/sysGenerator")
	public String sysGenerator() {
		return "generator/list";
	}

	@GetMapping("/sysJob")
	public String sysJob() {
		return "sysjob/list";
	}

	@GetMapping("/sysJobLog")
	public String sysJobLog() {
		return "sysjoblog/list";
	}

	@GetMapping("/sysFiles")
	public String sysFiles() {
		return "sysfiles/list";
	}
	
	@GetMapping("/index_223_rabbitmq")
	public String index_223_rabbitmq() {
		return "index_223-rabbitmq";
	}
	
}
